package com.beeantec.jnrerc.config.mybatisplus;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @Author: anthony
 * @Date: 2020/9/21 9:18
 */
@Configuration
@EnableTransactionManagement
@MapperScan("com.beeantec.jnrerc.mapper")

public class MybatisPlusAutoConfig {

    /**
     * mybatis-plus分页插件
     *
     * @return
     */
    @Bean
    public MybatisPlusInterceptor paginationInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));//Dbtype.数据库 可改成自己对应的数据库，当前为MySQL。
        return interceptor;

    }




//    /**
//     * 自动配置MybatisPlus参数
//     */
//    @Bean
//    @Primary
//    public MybatisPlusProperties mybatisPlusProperties() {
//        MybatisPlusProperties mybatisPlusProperties = new MybatisPlusProperties();
//        //MAPPER.XML所在位置
//        mybatisPlusProperties.setMapperLocations(new String[]{"classpath*:resources/mapper/*Mapper.xml"});
//        //扫描实体类，自动注册别名
//        mybatisPlusProperties.setTypeAliasesPackage("com.beeantec.jnrerc.entity");
//
//        mybatisPlusProperties.setGlobalConfig(globalConfig());
//        mybatisPlusProperties.setConfiguration(mybatisConfiguration());
//        return mybatisPlusProperties;
//    }


    private MybatisConfiguration mybatisConfiguration() {
        MybatisConfiguration mybatisConfiguration = new MybatisConfiguration();
        //查询结果下划线转驼峰
        mybatisConfiguration.setMapUnderscoreToCamelCase(true);
        //禁用二级缓存
        mybatisConfiguration.setCacheEnabled(false);
        //查询结果为空 也显示出来
        mybatisConfiguration.setCallSettersOnNulls(true);
        return mybatisConfiguration;
    }
}
